package com.stepshop.core.thread.spring;

import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

public class SpringExecutor {
	private static ThreadPoolTaskExecutor poolTaskExecutor =null;
	static{
		poolTaskExecutor = new ThreadPoolTaskExecutor();  
		//线程池所使用的缓冲队列  
		poolTaskExecutor.setQueueCapacity(200);  
		//线程池维护线程的最少数量  
		poolTaskExecutor.setCorePoolSize(5);  
		//线程池维护线程的最大数量  
		poolTaskExecutor.setMaxPoolSize(1000);  
		//线程池维护线程所允许的空闲时间  
		poolTaskExecutor.setKeepAliveSeconds(30000);  
		poolTaskExecutor.initialize();  
	}
	public static void execute(Runnable run) {
		poolTaskExecutor.execute(run);
		System.out.println("线程池中线程数目："+poolTaskExecutor.getPoolSize());
				
	}
	private SpringExecutor(){
		poolTaskExecutor = new ThreadPoolTaskExecutor();  
		//线程池所使用的缓冲队列  
		poolTaskExecutor.setQueueCapacity(200);  
		//线程池维护线程的最少数量  
		poolTaskExecutor.setCorePoolSize(5);  
		//线程池维护线程的最大数量  
		poolTaskExecutor.setMaxPoolSize(1000);  
		//线程池维护线程所允许的空闲时间  
		poolTaskExecutor.setKeepAliveSeconds(30000);  
		poolTaskExecutor.initialize();  
	}
}
